<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#tableContact').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<?php
/*echo $_POST[del];
exit;*/
if(isset($_POST[del]) && $_POST[del]!="")
{
 $sql = "DELETE FROM tb_device_model WHERE id =".$_POST[txtContId];
 $rows = $db->query($sql);
}
if(isset($_POST[txtContId]) && $_POST[txtContId] !='')
{
	$sql = "SELECT * FROM tb_device_model WHERE id =".$_POST[txtContId];
	$rows = $db->query($sql);
	if($db->affected_rows > 0)
	{
		$deviceRecord = $db->fetch_array($rows);
		//print_r($deviceRecord);
	}
}
?>
<script type="text/javascript" language="javascript">

function showPreloader()
{
	var returnVal = validateMapReport()
	if(returnVal == 1)
	{
		document.getElementById('popup_div').innerHTML = '<div id="loading_txt" >Loading...</div>';
		document.frm_map_filter.submit();
	}
}

function hidePreLoader()
{
	document.getElementById('popup_div').innerHTML = '&nbsp;';
}

function days_between(date1, date2) {

    var ONE_DAY = 1000 * 60 * 60 * 24

    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

	var difference_ms = date1_ms - date2_ms
	    
    return Math.round(difference_ms/ONE_DAY)

}

function validateEmail(id){
   var objMobileNo = document.getElementById(id);
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   if(!emailPattern.test(objMobileNo.value))
   {
	   //alert('Please enter valid email address');
	   //objMobileNo.focus();
	   //objMobileNo.select();
	   return false;
   }
   else return true;
 }

function mobileNoValid(id)
{
	objMobileNo = document.getElementById(id);
	if(document.getElementById(id).value.length != 10 || document.getElementById(id).value.search(/[^0-9\-()+]/g) != -1 )
	{
		//alert('Please enter valid 10 digit mobile number');
		//objMobileNo.focus();
		//objMobileNo.value="";
		return false;
	}
	else
	return true; 
	
}
var ajax1=new sack();

function validContForm(type)
{
	var f = 0;	
	if(document.getElementById('txtDevModelName').value == "" )
	{
		alert("Enter Device Model Name"); 
		document.getElementById('txtDevModelName').focus();
		f = 1;
		return false;
	}
	else f =0;
	if(document.getElementById('txtDevManuName').value == "" )
	{
		alert("Enter Device Manufacturer Name"); 
		document.getElementById('txtDevManuName').focus();
		f = 1;
		return false;
	}
	else f =0;
	if(document.getElementById('txtDevAliasName').value == "" )
	{
		alert("Enter Device Alias Name"); 
		document.getElementById('txtDevAliasName').focus();
		f = 1;
		return false;
	}
	else f =0;
	if(document.getElementById('txtChkImmobFunc').checked)
	{
		immobFunc = 1;
		smsOn = document.getElementById('txtOnSMS').value;
		smsOff = document.getElementById('txtOffSMS').value;
		if(smsOn == "")
		{
			alert("Enter SMS On Code"); 
			document.getElementById('txtOnSMS').focus();
			f = 1;
			return false;
		}
		else f = 0;
		
		if(smsOff == "")
		{
			alert("Enter SMS Off Code"); 
			document.getElementById('txtOffSMS').focus();
			f = 1;
			return false;
		}
		else f = 0;
	}
	else 
	{
		immobFunc = 0;
		smsOn = 0;
		smsOff = 0;
	}

	if(f==0)
	{
		//document.frmDeviceModel.submit();
		return true;
	}
	else return false;
	
}

function funEditUser(did,cid,act)
{
	//alert(uid)
	document.frmSubmit.txtContId.value = did;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}

function deleteUser(did,cid,act)
{
  if (confirm("Are you sure you want to delete")) {
	  document.frmSubmit.txtContId.value = did;
	document.frmSubmit.del.value = 'delete';
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
  }
}
var noOfDI;
var m1 = '<?php if($deviceRecord[tdm_noofInputs]) echo $deviceRecord[tdm_noofInputs]; else echo 0;?>';
for(j=0; j <= 30; j++)
{
	if(m1 == j)
	noOfDI +='<option value='+j+' selected=selected >'+j+'</option>';
	else
	noOfDI +='<option value='+j+'>'+j+'</option>';
}

var noOfDO;
var m2 = '<?php if($deviceRecord[tdm_noofOutputs]) echo $deviceRecord[tdm_noofOutputs]; else echo 0;?>';

for(j=0; j <= 30; j++)
{
	if(m2 == j)
	noOfDO +='<option value='+j+' selected=selected >'+j+'</option>';
	else
	noOfDO +='<option value='+j+'>'+j+'</option>';
}
var noOfAIO;
var m3 = '<?php if($deviceRecord[tdm_noofAnalog]) echo $deviceRecord[tdm_noofAnalog]; else echo 0;?>';

for(j=0; j <= 30; j++)
{
	if(m3 == j)
	noOfAIO +='<option value='+j+' selected=selected >'+j+'</option>';
	else
	noOfAIO +='<option value='+j+'>'+j+'</option>';
}
function showAnalogCalc(val)
{
	if(val > 0)
	{
		$("#AnalogCalc").css("display","block");
	}
	else
	{
		$("#AnalogCalc").css("display","none");
	}
}
function openSmsCode(e)
{
	if(e.checked)
	{
		$("#smsCode").css("display","block");
	}
	else
	{
		$("#smsCode").css("display","none");
	}
}

</script>
<form id="frmDeviceModel" name="frmDeviceModel" method="post" action="?ch=Device"> 
<input type="hidden" name="txtContId" id="txtContId" value="<?php echo $_POST[txtContId];?>" />
<input type="hidden" name="txtClientId" id="txtClientId" value="<?php echo $_POST[txtClientId];?>" />
<table class="gridform_final">
<tr><th colspan="6">New Device Details</th></tr>
  <tr>
    <td width="20%" align="right">Model Name</td>
    <td width="15%" align="left">
        <input type="text" name="txtDevModelName" id="txtDevModelName" maxlength="15" tabindex="1" value="<?php echo $deviceRecord[model];?>" />
    </td>
    <td width="20%" align="right">Manufacturer Name</td>
    <td width="15%" align="left">
        <input type="text" name="txtDevManuName" id="txtDevManuName" maxlength="25" tabindex="2" value="<?php echo $deviceRecord[tdm_manuName];?>" />
    </td>
    <td width="20%" align="right">Alias Name</td>
    <td width="15%" align="left">
        <input type="text" name="txtDevAliasName" id="txtDevAliasName" maxlength="15" tabindex="3" value="<?php echo $deviceRecord[tdm_aliasName];?>" />
    </td>
  </tr>
  <tr>
    <td align="right">No. of Digital Inputs</td>
    <td align="left">
    	<select name="selDigitIn" id="selDigitIn" tabindex="4">
        	<script language="javascript">
				document.write(noOfDI);
			</script>
        </select>
    </td>
    <td align="right">No. of Digital Outputs</td>
    <td align="left">
    	<select name="selDigitOut" id="selDigitOut" tabindex="5">
        	<script language="javascript">
				document.write(noOfDO);
			</script>
        </select>
    </td>
    <td align="right">No. of Analog Inputs</td>
    <td align="left">
    	<select name="selAnalogIO" id="selAnalogIO" tabindex="6" onchange="showAnalogCalc(this.value);">
        	<script language="javascript">
				document.write(noOfAIO);
			</script>
        </select>
    </td>
  </tr>  
  <tr>
    <td align="right">Immobilize / Speed Alaram Available ?</td>
    <td align="left">
        <input type="checkbox" name="txtChkImmobFunc" id="txtChkImmobFunc" value="1" tabindex="7" onchange="openSmsCode(this)" <?php if($deviceRecord[tdm_immobFunc]) echo 'checked="checked"';?>/>&nbsp;Yes
    </td>
    
     <td colspan="4">
     <span id="smsCode" style="display:<?php if($deviceRecord[tdm_immobFunc] == 1) echo 'display'; else echo 'none';?>;">SMS Format to ON:&nbsp;<input type="text" name="txtOnSMS" id="txtOnSMS" tabindex="8" value="<?php echo $deviceRecord[tdm_smsOnCode];?>" />&nbsp;&nbsp;SMS Format to OFF:&nbsp;<input type="text" name="txtOffSMS" id="txtOffSMS" tabindex="9" value="<?php echo $deviceRecord[tdm_smsOffCode];?>" /></span>
     </td>
    
  </tr>
  <tr>
    <td style="text-align:center" colspan="6">
  
    <?php if(isset($_POST[txtContId]) && $_POST[txtContId]!='')  { ?>
	  <input type="submit" name="cmdUpdateModel" id="cmdUpdateModel" value="Update" class="save_btn" tabindex="10" onclick="return validContForm('update');"/> 
	<?php } else { ?>
      <input type="submit" name="cmdAddModel" id="cmdAddModel" value="Add" class="save_btn" tabindex="11" onclick="return validContForm('add');" />    
    <?php } ?>
      <input type="button" name="map_cancel_btn" id="map_cancel_btn" value="Cancel" class="save_btn" onclick="location.href='index.php?ch=deviceModel';" tabindex="7" /> 
  </tr>  
</table>
</form>
<br />
<?php
$selInsur = "SELECT * FROM tb_device_model";
$resInsur = $db->query($selInsur);
?>
<table class="gridform_final" id="tableContact">
<thead>
    <tr>
    	<th width="2%">#</th>
        <th width="10%">Model Name</th>
        <th width="25%">Model Manuf.</th>
        <th width="20%">Model Alias</th>
        <th width="10%">No. of Inputs</th>
        <th width="10%">No. of Outputs</th>
        <th width="10%">No. of Analog</th>
        <th width="10%">Immob Func.</th>
        <th width="5%">Edit</th>
        <!--<th width="3%">Delete</th>-->
   </tr>
</thead>
<tbody>   
	 <?php 
	 if($db->affected_rows)
	 {
		 $i = 0;
    while($fetInsur = @mysql_fetch_assoc($resInsur)) 
    { 
    ?>
   <tr>
    <td><?php echo ++$i;?></td>
    <td><?php echo ucfirst($fetInsur[model]);?></td>
    <td><?php echo ucfirst($fetInsur[tdm_manuName]);?></td>
    <td><?php echo ucfirst($fetInsur[tdm_aliasName]);?></td>
    <td><?php echo $fetInsur[tdm_noofInputs];?></td>
    <td><?php echo $fetInsur[tdm_noofOutputs];?></td>
    <td><?php echo $fetInsur[tdm_noofAnalog]; ?></td>
    <td><?php if($fetInsur[tdm_immobFunc]) echo "Yes"; else echo "No";?></td>
    <td><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $fetInsur[id];?>','<?php echo $_SESSION[clientID];?>','?ch=deviceModel')" /></td>
	<!--<td><img src="../../images/delete.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="deleteUser('<?php echo $fetInsur[id];?>','<?php echo $_SESSION[clientID];?>','?ch=viewContact','del')" /></td>-->
  </tr>
  <?php
	}
	 }
  ?>
</tbody>  
</table>

<form name="frmSubmit" id="frmSubmit" method="post">
    <input type="hidden" name="txtContId" id="txtContId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
	<input type="hidden" name="del" id="del"/>

</form>